package cn.hnbjx.prepaid.service;

import cn.hnbjx.prepaid.dao.NewsDao;
import cn.hnbjx.prepaid.pojo.News;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Slf4j
@Service
public class NewsService {
    @Autowired
    private NewsDao newsDao;

    public PageInfo<News> allNews(int page, String key) {
        PageHelper.startPage(page,10);
        List<News> news = newsDao.allNews(key);
        PageInfo<News> newsPageInfo = new PageInfo<>(news);
        return newsPageInfo;
    }
    public PageInfo<News> apiallNews(int page, int type) {
        PageHelper.startPage(page,10);
        List<News> news = newsDao.apiallNews(type);
        PageInfo<News> newsPageInfo = new PageInfo<>(news);
        return newsPageInfo;
    }
    public void insertNews(News news){
        newsDao.insert(news);
    }
    public Integer updateNews(News news){
       return newsDao.updateNews(news);
    }
    public News findNews(Integer id){
      return   newsDao.findNews(id);
    }
    public void delete(Integer id){
         newsDao.delete(id);
    }
}
